$.fn.extend({//添加滚轮事件//
      mousewheel:function(Func){
            return  this.each(function(){
                  var  _delta  =  this;
                    delta  =  0;//滚动方向
                  if($.browser.msie||$.browser.safari){
                        _delta.onmousewheel=function(){  delta  =  event.wheelDelta;event.returnValue  =  false;Func  &&  Func.call(_delta);};
                  }else{
                        _delta.addEventListener("DOMMouseScroll",function(e){
                              delta  =  e.detail>0?-1:1;
                              e.preventDefault();
                              Func  &&  Func.call(_delta);
                        },false);  
                  }
            });
      }
})
$(function(){            
      $.fn.oScroll  =  function(set)  {
            var  defaults  =  {
                  s_width:"7px",
                  slbg_color:"#eaeaea",
                  sbg_color:"#999a9a",
                  slbg:"",
                  b_radius:"10px"
            };                  
            var  ie6=navigator.userAgent.indexOf("MSIE  6.0"),ie7=navigator.userAgent.indexOf("MSIE  7.0");
            var  set  =  $.extend(defaults,  set);
                  var  objdiv=$(this).attr("class");
                  var  setdiv=$(this).parent().attr("class");
            var  th=this.height(),sh=$("."+setdiv).height()-3;//文本内容高度th  ,窗口高度sh
            var  slip,y,_y,Slt_H;
            $(window).resize(function(){
                  th=$("."+objdiv).height();
                  sh=$("."+setdiv).height()-3;//文本内容高度th  ,窗口高度sh
            })
            if(th>sh){
                  if($(".srollside").attr("class")==undefined){
                        $("."+setdiv).append("<div  class=\"srollside\"><span  class=\"srollside_line\"></span></div>");            
                  }
                  $(".srollside_line").css({"top":0+"px","position":"relative","right":0+"px","background-color":set.slbg_color,"width":set.s_width,"height":"64px","display":"inline-block","border-radius":set.b_radius,"background-image":set.slbg,"background-repeat":  "repeat-y","margin":"0px  0px  0px  0px"})
                  $(".srollside").css({"width":set.s_width,"height":"303px","position":"relative","float":"right","border":"1px  solid  #ccc","background-color":set.sbg_color,"border-radius":set.b_radius,"right":0+"px",  "top":0+"px","z-index":9999,"display":"inline-block"})
                  $(".srollside").css({height:sh})//滚动条高度根据窗口高度改变
                  $(".srollside_line").css({height:sh*sh/th})    //滚动条中间那个小条条的高度根据内容与窗口比改变
                  var  s_height=$(".srollside").height(),                                        sl_height=$(".srollside_line").height()//变化后新滚动条高度参数
                  var  s_top=$(".srollside").offset().top,/*19*/    sl_top=$(".srollside_line").offset().top/*20*/
                  var  deltaM=0;
                  $(window).resize(function(){
                        $(".srollside").css({height:sh});//滚动条高度根据窗口高度改变
                        $(".srollside_line").css({height:sh*sh/th})  ;  //滚动条中间那个小条条的高度根据内容与窗口比改变
                        $(".srollside_line").css({top:Slt_H*sh})
                        if($(".srollside_line").offset().top-$(".srollside").offset().top+$(".srollside_line").height()>=$(".srollside").height()){
                              $(".srollside_line").css({top:$(".srollside").height()-$(".srollside_line").height()})
                              $("."+objdiv).css({top:-($(".srollside").height()-$(".srollside_line").height())/$(".srollside").height()*th});
                        }
                        deltaM=-($(".srollside_line").offset().top-$(".srollside").offset().top-1)/7;
                  })
                  $("."+setdiv).mousewheel(function(){//滚轮事件
                        th=$("."+objdiv).height();
                        sh=$("."+setdiv).height();
                        s_height=$(".srollside").height();
                        sl_height=$(".srollside_line").height();
                        var  i=0;
                        if(delta>0){i++;}
                        else  if(delta<0){i--;}
                        deltaM=i+deltaM;
                        if(-deltaM<0){deltaM=0;}
                        if(-deltaM*7>s_height-sl_height){deltaM=-(s_height-sl_height)/7;}
                        $("input.test").val(deltaM*7);
                        $(".srollside_line").css({top:-deltaM*7});
                        var  thisTop  =  (-deltaM*7)*(th-sh)/(s_height-sl_height);
                        $("."+objdiv).css({top:-thisTop});
                        Slt_H=(($(".srollside_line").offset().top-$(".srollside").offset().top-1)/$(".srollside").height());
                  })
                  $(".srollside_line").mousedown(function  (event){
                        var  e  =  event  ||  window.event;
                        slip=true;
                        sl_top=$(".srollside_line").offset().top;
                        _y  =  e.pageY-sl_top;//小条条的相对坐标Y      
      //      变色            $(".srollside_line").css({"background-Color":"#abcdef  "})
                        $(document).mousemove(function  (e){            
                              y  =    e.pageY-s_top;//滚动条相对坐标Y
                              if(slip){
                                    th=$("."+objdiv).height();
                                    sh=$("."+setdiv).height();
                                    s_height=$(".srollside").height();
                                    sl_height=$(".srollside_line").height();
                                    $(".srollside_line").css({top:y-_y})
                                    if(y-_y<0){$(".srollside_line").css({top:0});}
                                    if(y-_y>s_height-sl_height){$(".srollside_line").css({top:s_height-sl_height})}
                                    var  nsl_top=$(".srollside_line").offset().top-$(".srollside").offset().top-1;
                                    deltaM=-nsl_top/7;
                                    var  thisTop  =  -(deltaM*7)*(th-sh)/(s_height-sl_height);
                                    $("."+objdiv).css({top:-thisTop});
                              }
                              var  a=y-_y;
                              var  b=s_height-sl_height;
                              Slt_H=(($(".srollside_line").offset().top-$(".srollside").offset().top-1)/$(".srollside").height());
                        })
                        return  false;
                  })
                  $(document).mouseup(function  (){
                        slip=false;
                        sl_top=$(".srollside_line").offset().top;
      //                  $(".srollside_line").css({"background-Color":"#eaeaea  "})
                        return  false;
                  })      
                        
            if($.browser.msie){document.execCommand("BackgroundImageCache",  false,  true);}              
                  return  this;
            }
            else{$(".srollside").css({"display":"none"})}            
            };
})